package com.trip.api;

import com.trip.config.AppUser;
import com.trip.dao.tables.UserCollection;
import com.trip.dao.tables.pojos.UserCollectionDomain;
import com.trip.service.CollectionService;
import com.trip.util.AuthUtil;
import com.trip.vo.CollectionIndexVo;
import com.trip.vo.PlaceAndExperienceListItemVo;
import com.trip.vo.SingleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by hc24 on 2017/10/4.
 */
@AppUser
@Validated
@Api("User Collection")
@RestController
@RequestMapping("collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    @ApiOperation("Add Place or Experience to my collection")
    @RequestMapping(value = "",method = RequestMethod.POST)
    public ControllerResult addCollection(@RequestHeader @ApiParam(name = "authToken", value = "Auth Token",required = true) String authToken,
                                          @RequestBody SingleVo<String> paeId){
        collectionService.create(AuthUtil.getUserId(authToken),paeId.getValue(),null);
        return ControllerResult.success();
    }

    @ApiOperation(("Cancel collect"))
    @RequestMapping(value = "",method = RequestMethod.DELETE)
    public ControllerResult cancelCollection(@RequestHeader @ApiParam(name = "authToken", value = "Auth Token",required = true) String authToken,
                                             @RequestParam String paeId){
        collectionService.delete(paeId,AuthUtil.getUserId(authToken));
        return ControllerResult.success();
    }

    @ApiOperation("My collection list")
    @RequestMapping(value = "",method = RequestMethod.GET)
    public ControllerResult<List<PlaceAndExperienceListItemVo>> queryList(@RequestHeader @ApiParam(name = "authToken", value = "Auth Token",required = true) String authToken,
                                                                          @NotNull @RequestParam Integer type){
        return ControllerResult.success(collectionService.queryList(type,AuthUtil.getUserId(authToken)));
    }


    @ApiOperation("Collection index")
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public ControllerResult<CollectionIndexVo> queryIndex(@RequestHeader @ApiParam(name = "authToken", value = "Auth Token",required = true) String authToken,
                                                          @NotNull @RequestParam Integer type){
        return ControllerResult.success(collectionService.queryIndex(type,AuthUtil.getUserId(authToken)));
    }

}
